{{- /* Collection Navigation */ -}}
{{- $params := partial "function/params.html" -}}

{{- if .Params.collections | and $params.collectionNavigation -}}
  {{- $collectionTerms := .GetTerms "collections" -}}
  {{- range $collectionTerms -}}
    {{- $termLink := printf `<a href="%v">%v <span>%v・%v</span></span></a>`
      (partial "function/escapeurl.html" .RelPermalink)
      (dict "Class" "fa-solid fa-layer-group fa-fw" | partial "plugin/icon.html")
      (T "collection")
      .LinkTitle
    -}}
    <div class="collection-card">
      <div class="collection-title text-secondary">
        {{- dict "Collections" $termLink | T "single.includedIn.collections" | strings.FirstUpper | safeHTML }} {{ .Pages.Len -}}
      </div>
      <div class="collection-nav">
        {{/*  TODO JS 实现 reverse 翻转顺序  */}}
        {{- $pages := (where .Pages "Params.Weight" "!=" nil) | append (where .Pages "Params.Weight" "eq" nil).ByDate -}}
        {{- with $pages.Next $ -}}
          {{- $capitalizeTitles := .Param "capitalizeTitles" -}}
          {{- $title := .Params.shortTitle | default .LinkTitle -}}
          {{- $title = cond $capitalizeTitles (title $title) $title -}}
          <a href="{{ .RelPermalink }}" class="collection-nav-item" rel="prev" title="{{ $title }}">
            {{- dict "Class" "fa-solid fa-angle-left fa-fw" | partial "plugin/icon.html" -}}
            <span>{{ $title }}</span>
          </a>
        {{- end -}}
        {{- with $pages.Prev $ -}}
          {{- $capitalizeTitles := .Param "capitalizeTitles" -}}
          {{- $title := .Params.shortTitle | default .LinkTitle -}}
          {{- $title = cond $capitalizeTitles (title $title) $title -}}
          <a href="{{ .RelPermalink }}" class="collection-nav-item" rel="next" title="{{ $title }}">
            <span>{{ $title }}</span>
            {{- dict "Class" "fa-solid fa-angle-right fa-fw" | partial "plugin/icon.html" -}}
          </a>
        {{- end -}}
      </div>
    </div>
  {{- end -}}
{{- end -}}
